home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / bbs / pad321.zip / IN.MH < prev    next >
Text File  |  1996-08-21  |  13KB  |  459 lines

  1. // (C) 1995 Stefan Xenos
  2. //
  3.  
  4. #ifndef __IN_MH
  5. #define __IN_MH
  6.  
  7. #ifndef __UPCHAR_MH
  8. #include "upchar.mh"
  9. #endif
  10.  
  11. #ifndef __COUNTCHA_MH
  12. #include "countcha.mh"
  13. #endif
  14.  
  15. #ifndef __STRIPSTR_MH
  16. #include "stripstr.mh"
  17. #endif
  18.  
  19. #ifndef __INSETUP_MH
  20. #include "insetup.mh"
  21. #endif
  22.  
  23. #define ANI_SPINNER     "/|\\-"
  24. #define ANI_FILL        "░▒▓█▓▒░ "
  25. #define ANI_FILL_SPIN   "▄▌▀▐"
  26. #define ANI_META        "_-+|│ìïî|┤┐─═≡=-∙°ºouUÜÖo"
  27. #define ANI_QUESTION    "¿?"
  28. #define ANI_LINES       "┐┬┌├└┴┘┤"
  29. #define ANIMATION_OFF   0,""
  30. //#define ANI_WEIRD       "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤Y╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■"
  31.  
  32. #define   KB_BS                 (8)
  33. #define   KB_CR                 (13)
  34.  
  35. #define   KB_CTRL_@             (0)
  36. #define   KB_CTRL_A             (1)
  37. #define   KB_CTRL_B             (2)
  38. #define   KB_CTRL_C             (3)
  39. #define   KB_CTRL_D             (4)
  40. #define   KB_CTRL_E             (5)
  41. #define   KB_CTRL_F             (6)
  42. #define   KB_CTRL_G             (7)
  43. #define   KB_CTRL_H             (8)
  44. #define   KB_CTRL_I             (9)
  45. #define   KB_CTRL_J             (10)
  46. #define   KB_CTRL_K             (11)
  47. #define   KB_CTRL_L             (12)
  48. #define   KB_CTRL_M             (13)
  49. #define   KB_CTRL_N             (14)
  50. #define   KB_CTRL_O             (15)
  51. #define   KB_CTRL_P             (16)
  52. #define   KB_CTRL_Q             (17)
  53. #define   KB_CTRL_R             (18)
  54. #define   KB_CTRL_S             (19)
  55. #define   KB_CTRL_T             (20)
  56. #define   KB_CTRL_U             (21)
  57. #define   KB_CTRL_V             (22)
  58. #define   KB_CTRL_W             (23)
  59. #define   KB_CTRL_X             (24)
  60. #define   KB_CTRL_Y             (25)
  61. #define   KB_CTRL_Z             (26)
  62.  
  63. #define   KB_CTRL_PGUP          (128+4)
  64. #define   KB_F11                (128+5)
  65. #define   KB_F12                (128+6)
  66. #define   KB_SHIFT_F11          (128+7)
  67. #define   KB_SHIFT_F12          (128+8)
  68. #define   KB_CTRL_F11           (128+9)
  69. #define   KB_CTRL_F12           (128+10)
  70. #define   KB_ALT_F11            (128+11)
  71. #define   KB_ALT_F12            (128+12)
  72. #define   KB_CTRL_UP            (128+13)
  73.  
  74. #define   KB_CTRL_CENTER        (128+15)
  75.  
  76. #define   KB_CTRL_DOWN          (128+17)
  77. #define   KB_CTRL_INS           (128+18)
  78. #define   KB_CTRL_DEL           (128+19)
  79.  
  80. #define   KB_ALT_UP             (128+24)
  81.  
  82. #define   KB_ALT_LEFT           (128+27)
  83.  
  84. #define   KB_ALT_RIGHT          (128+29)
  85.  
  86. #define   KB_ALT_DOWN           (128+32)
  87.  
  88. #define   KB_F1                 (128+59)
  89. #define   KB_F2                 (128+60)
  90. #define   KB_F3                 (128+61)
  91. #define   KB_F4                 (128+62)
  92. #define   KB_F5                 (128+63)
  93. #define   KB_F6                 (128+64)
  94. #define   KB_F7                 (128+65)
  95. #define   KB_F8                 (128+66)
  96. #define   KB_F9                 (128+67)
  97. #define   KB_F10                (128+68)
  98.  
  99. #define   KB_HOME               (128+71)
  100. #define   KB_UP                 (128+72)
  101. #define   KB_PGUP               (128+73)
  102.  
  103. #define   KB_LEFT               (128+75)
  104. #define   KB_CENTER             (128+76)
  105. #define   KB_RIGHT              (128+77)
  106.  
  107. #define   KB_END                (128+79)
  108. #define   KB_DOWN               (128+80)
  109. #define   KB_PGDN               (128+81)
  110. #define   KB_INS                (128+82)
  111. #define   KB_DEL                (128+83)
  112. #define   KB_SHIFT_F1           (128+84)
  113. #define   KB_SHIFT_F2           (128+85)
  114. #define   KB_SHIFT_F3           (128+86)
  115. #define   KB_SHIFT_F4           (128+87)
  116. #define   KB_SHIFT_F5           (128+88)
  117. #define   KB_SHIFT_F6           (128+89)
  118. #define   KB_SHIFT_F7           (128+90)
  119. #define   KB_SHIFT_F8           (128+91)
  120. #define   KB_SHIFT_F9           (128+92)
  121. #define   KB_SHIFT_F10          (128+93)
  122. #define   KB_CTRL_F1            (128+94)
  123. #define   KB_CTRL_F2            (128+95)
  124. #define   KB_CTRL_F3            (128+96)
  125. #define   KB_CTRL_F4            (128+97)
  126. #define   KB_CTRL_F5            (128+98)
  127. #define   KB_CTRL_F6            (128+99)
  128. #define   KB_CTRL_F7            (128+100)
  129. #define   KB_CTRL_F8            (128+101)
  130. #define   KB_CTRL_F9            (128+102)
  131. #define   KB_CTRL_F10           (128+103)
  132.  
  133. #define   KB_CTRL_LEFT          (128+115)
  134. #define   KB_CTRL_RIGHT         (128+116)
  135. #define   KB_CTRL_END           (128+117)
  136. #define   KB_CTRL_PGDN          (128+118)
  137. #define   KB_CTRL_HOME          (128+119)
  138.  
  139. // Global variables -------------------------------------------------------
  140.  
  141. int: maxAnimationPos, animationPos, num_show_response, speed;
  142. string: animation, animationColour, textColour;
  143.  
  144. // The following variables control the behaviour of the input_list_ani routine
  145.  
  146. void animationOff () {
  147.   maxAnimationPos := 0;
  148.   animation := "";
  149.   }
  150.  
  151. void useAnimation (string: newAnimation, string: newAnimationColour, 
  152.   string: newTextColour, int: newAnimationSpeed) {
  153.  
  154.   speed := newAnimationSpeed;
  155.   animation := newAnimation;
  156.   animationColour := newAnimationColour;
  157.   textColour := newTextColour;
  158.   animationPos := 1;
  159.   maxAnimationPos := strlen (animation);
  160.   if (newAnimationSpeed = 0) animationOff ();
  161.   }
  162.  
  163. int waitKey (int: maxLength) {
  164.   int: counter;
  165.   for (counter := 0; (counter < maxLength); counter := counter + 3) {
  166.     if (kbhit ()) return True;
  167.     sleep (3);
  168.     };
  169.   return False;
  170.   }
  171.  
  172. void keystallAni () {
  173.   int: counter;
  174.   if (maxAnimationPos = 0) {
  175.     for (;kbhit () = 0;);
  176.     return;
  177.     };
  178.   if (kbhit ()) return;
  179.   for (;;) {
  180.     print (animation [animationPos]);
  181.     animationPos := animationPos + 1;
  182.     if (animationPos > maxAnimationPos) animationPos := 1;
  183.     print (AVATAR_LEFT);
  184.     if (waitKey (speed)) {
  185.       if (usr.video = 0) {
  186.         print ('\b');
  187.         print (' ');
  188.         print ('\b');
  189.         return;
  190.         };
  191.       print (" ");
  192.       print (AVATAR_LEFT);
  193.       return;
  194.       };
  195.     if (usr.video = 0) {
  196.       print ('\b');
  197.       };
  198.     };
  199.   }
  200.  
  201. void flushInput () {
  202.   for (;kbhit ();getch ());
  203.   }
  204.  
  205. char getchExtended () {
  206.   int: result;
  207.  
  208.   result := getch ();
  209.   if (usr.video = 0) return result;
  210.   if (result = 0) {
  211.     if (waitKey (20) = False) {
  212.       return 0;
  213.       };
  214.     return 128 + getch ();
  215.     };
  216.   if (result = 27) {
  217.     if (waitKey (20) = False) {
  218.       return 27;
  219.       };
  220.     result := getch ();
  221.     if (result <> '[') {
  222.       return result;
  223.       };
  224.     do {
  225.       if (waitKey (20) = False)
  226.         return '[';
  227.  
  228.       result := upChar (getch ());
  229.       } while ((result >= '0') and (result <= '9'));
  230.  
  231.     if (result = 'A') return KB_UP;
  232.     if (result = 'B') return KB_DOWN;
  233.     if (result = 'C') return KB_RIGHT;
  234.     if (result = 'D') return KB_LEFT;
  235.     if (result = 'H') return KB_HOME;
  236.     if (result = 'K') return KB_END;
  237.     if (result = 'L') return KB_CTRL_HOME;
  238.     if (result = 'M') return KB_CTRL_PGUP;
  239.     };
  240.  
  241.   return result;
  242.   }
  243.  
  244. char getchAni () {
  245.   char: result;
  246.  
  247.   print (animationColour);
  248.   if (maxAnimationPos > 0) keystallAni ();
  249.  
  250.   result := getchExtended ();
  251.  
  252.   print (textColour);
  253.   vidsync ();
  254.  
  255.   return result;
  256.   }
  257.  
  258. void readStrAni (Ref string: theString) {
  259.   int: idx, slen;
  260.   char: key;
  261.   int: counter;
  262.  
  263.   idx := 1;
  264.   slen := 0;
  265.  
  266.   theString := "";
  267.  
  268.   for (;;) {
  269.     if (idx = slen + 1) {
  270.       key := getchAni ();
  271.       }
  272.     else key := getchExtended ();
  273.  
  274.     if (key = KB_BS) {
  275.       if (idx > 1) {
  276.         idx := idx - 1;
  277.         slen := slen - 1;
  278.         if (idx = slen + 1) {
  279.           theString := substr (theString,1,slen);
  280.           print ('\b');
  281.           print (" ");
  282.           print ('\b');
  283.           }
  284.         else {
  285.           string: newString;
  286.           newString := substr (theString, idx+1, slen - idx + 1);
  287.  
  288.           print (AVATAR_LEFT);
  289.           theString := substr (theString,1,idx-1) + newString;
  290.           print (newString + " ");
  291.           for (counter := 0; counter <= strlen (newString); counter := counter + 1) {
  292.             print (AVATAR_LEFT);
  293.             };
  294.           };
  295.         };
  296.       }
  297.     else if (key = KB_CR) {
  298.       print ("\n");
  299.       return;
  300.       }
  301.     else if (key = KB_HOME) {
  302.       for (; idx > 1; idx := idx - 1) {
  303.         print (AVATAR_LEFT);
  304.         };
  305.       }
  306.     else if (key = KB_END) {
  307.       for (; idx <= slen; idx := idx + 1) {
  308.         print (theString [idx]);
  309.         };
  310.       }
  311.     else if ((key = KB_LEFT) and (idx > 1)) {
  312.       print (AVATAR_LEFT);
  313.       idx := idx - 1;
  314.       }
  315.     else if ((key = KB_CTRL_LEFT) and (idx > 1)) {
  316.       counter := idx - 1;
  317.       while ((counter > 1) and (theString [counter] = ' ')) {
  318.         counter := counter - 1;
  319.         };
  320.       while ((counter > 1) and (theString [counter] <> ' ')) {
  321.         counter := counter - 1;
  322.         };
  323.       if ((slen > 1) and (theString [counter] = ' ') and (counter > 1))
  324.         counter := counter + 1;
  325.       for (;counter < idx; idx := idx - 1) {
  326.         print (AVATAR_LEFT);
  327.         };
  328.       vidsync ();
  329.       }
  330.     else if ((key = KB_CTRL_RIGHT) and (idx <= slen )) {
  331.       counter := idx;
  332.       while ((counter <= slen) and (theString [counter] = ' ')) {
  333.         counter := counter + 1;
  334.         };
  335.       while ((counter <= slen) and (theString [counter] <> ' ')) {
  336.         counter := counter + 1;
  337.         };
  338.       for (;counter > idx; idx := idx + 1) {
  339.         print (theString [idx]);
  340.         };
  341.       vidsync ();
  342.       }
  343.     else if ((key = KB_RIGHT) and (idx <= slen)) {
  344.       print (theString [idx]);
  345.       idx := idx + 1;
  346.       }
  347.     else if (key = KB_CTRL_Y) {
  348.       for (;idx > 1; idx := idx - 1) {
  349.         print ('\b');
  350.         };
  351.       slen := 0;
  352.       print (AVATAR_CLEOL);
  353.       theString := "";
  354.       }
  355.     else if ((key = KB_DEL) and (idx <= slen)) {
  356.       string: newString;
  357.       slen := slen - 1;
  358.       newString := substr (theString, idx+1, slen - idx + 1);
  359.       theString := substr (theString,1,idx-1) + newString;
  360.       print (newString + " ");
  361.       for (counter := 0; counter <= strlen (newString); counter := counter + 1) {
  362.         print (AVATAR_LEFT);
  363.         };
  364.       }
  365.     else if ((key = KB_CTRL_L) or (key = KB_CTRL_W)) {
  366.       for (counter := 1; counter < idx; counter := counter + 1) {
  367.         print ('\b');
  368.         };
  369.       print (theString);
  370.       vidsync ();
  371.       for (counter := 0; counter < slen - idx + 1; counter := counter + 1) {
  372.         print (AVATAR_LEFT);
  373.         };
  374.       vidsync ();
  375.       }
  376.     else if (key > 127) {
  377.       }
  378.     else {
  379.       idx := idx + 1;
  380.       slen := slen + 1;
  381.       if (idx = slen + 1) {
  382.         print (key);
  383.         theString [idx - 1] := key;
  384.         }
  385.       else {
  386.         string: newString;
  387.         print (key);
  388.         vidsync ();
  389.         newString := substr (theString,idx - 1,slen + 1 - idx);
  390.         print (newString);
  391.         vidsync ();
  392.         theString := substr (theString,1,idx - 2);
  393.         theString [idx - 1] := key;
  394.         vidsync ();
  395.         theString := theString + newString;
  396.         for (counter := 0; counter < slen - idx + 1; counter := counter + 1) {
  397.           print (AVATAR_LEFT);
  398.           };
  399.         };
  400.       };
  401.     };
  402.   }
  403.  
  404. string choiceStr (string: values) {
  405.   int: idx, tidx;
  406.   string: result;
  407.   tidx := 2;
  408.   stripStr (values, "\r\n\b");
  409.   result [1] := '[';
  410.   for (idx := 1; idx < strlen (values); idx := idx + 1) {
  411.     result [tidx] := values [idx];
  412.     tidx := tidx + 1;
  413.     result [tidx] := ',';
  414.     tidx := tidx + 1;
  415.     };
  416.   result [tidx] := values [idx];
  417.   result := result + "]:";
  418.   return result;
  419.   }
  420.  
  421. char input_list_ani (string: values, string: error, string: prompt) {
  422.   char: key;
  423.   string: choices;
  424.   string: chStr;
  425.  
  426.   chStr := choiceStr (values);
  427.  
  428.   if (usr.ibmchars) {
  429.     useAnimation (KEY_ANI, KEY_ANI_COL, KEY_TEXT_COL, KEY_ANI_SPEED);
  430.     }
  431.   else useAnimation (KEY_ANI_NOIBM, KEY_ANI_COL, KEY_TEXT_COL, KEY_ANI_SPEED);
  432.   choices := strupper (values);
  433.   for (;;) {
  434.     print (PROMPT_COL);
  435.     print (prompt);
  436.     if (SHOW_CHOICES) print (" " + CHOICE_COL + chStr + " ");
  437.  
  438.     key := upChar (getchAni ());
  439.  
  440.     if (SHOW_USER_INPUT) print (key);
  441.     print ('\n');
  442.     if (countChar (choices, key)) {
  443.       return key;
  444.       };
  445.     print (ERROR_COL);
  446.     print (error);
  447.     };
  448.   }
  449.  
  450. void input_str_ani (Ref string: theString) {
  451.   if (usr.ibmchars) {
  452.     useAnimation (STR_ANI, STR_ANI_COL, STR_TEXT_COL, STR_ANI_SPEED);
  453.     }
  454.   else useAnimation (STR_ANI_NOIBM, STR_ANI_COL, STR_TEXT_COL, STR_ANI_SPEED);
  455.   readStrAni (theString);
  456.   }
  457.  
  458. #endif
  459.